import * as VueResource from "vue-resource";
import {routeService}  from "./routeService";


export function dataService () {

    // var baseUrl="http://192.168.0.9:887/csp/";
    // var baseUrl="http://192.168.0.9:8080/api/";
    var baseUrl="csp/";
    // var baseUrl="https://cspfrontdev.vip56.cn/csp/";

    var DefaultBlockSize:number = 1024 * 32 // Default to 32KB
    
    var upload = function () {
        Vue.use(VueResource);
        return Vue.http.get('../../test.json', {}, {
            headers: {
                "X-Requested-With": "XMLHttpRequest"
            },
            emulateJSON: true
        }).then(function(response) {
            var data = response.data['data'];
            return data;
        }, function(response) {
            // handle error
            return response;
        })
    };
   var Storage={
       AquireStorageSharedSigniture:function(){
           Vue.use(VueResource);
            return Vue.http.get(baseUrl+'Storage/AquireStorageSharedSigniture?containerName='+'avatar-container',{},
                {
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data;
                return data;
            }, function(response) {
                // handle error
                return response;
            })
       }
   }
    var Attachment= {
        getAttachment: function(id:string){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Attachment.getAttachment(id),{
            headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        }

    }
   

    var Area={
        //获取总
        getAllArea:function(provincecode:string,citycode:string,isreturn:boolean){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Area.getAllArea(provincecode,citycode,isreturn),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //获取省
        getProvince:function(){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Area.getProvince(),{},
                {
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //获取市
        getCity:function(provinceCode:string){
            if(!provinceCode){
                return;
            }
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Area.getCity(provinceCode),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })

        },
        //获取区
        getCountry:function(cityCode:string){
            if(!cityCode){return}
           Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Area.getCounty(cityCode),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        }
    };
    var CspInquiry={
        //获取发布询价列表
        getCspInquiryList:function(
                CspInquiryCode:string,
                CspInquiryChildCode:string,
                status:string,
                startTime:string,
                endTime:string,
                startAddress:string,
                endAddress:string,
                skip:number,
                count:number
            ){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.CspInquiry.getCspInquiryList(
                CspInquiryCode,
                CspInquiryChildCode,
                status,
                startTime,
                endTime,
                startAddress,
                endAddress,
                skip,
                count
            ),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest",
                    'Access-Control-Allow-Origin': "*"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //获取发布询价详情
        getCspInquiry:function(id:string){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.CspInquiry.getCspInquiry(id),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //添加发布询价
        //添加发布询价的参数格式后面再加
        //attention!!!
        addCspInquiry:function(submitInquiry){
            Vue.use(VueResource);
            return Vue.http.post(baseUrl+routeService.CspInquiry.addCspInquiry,submitInquiry,
        
                {
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: false
            }).then(function(response) {
                // console.info('response',response);
                var data = response.data;
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //修改发布询价
        editCspInquiry:function(id:string){
            Vue.use(VueResource);
            return Vue.http.put(baseUrl+routeService.CspInquiry.editCspInquiry(id),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //删除发布询价
        deleteCspInquiry:function(id:string){
            Vue.use(VueResource);
            return Vue.http.delete(baseUrl+routeService.CspInquiry.deleteCspInquiry(id),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: false
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },

    };
    var CspOrder={
        //获取发布订单列表
        getCspOrderList:function(
                orderId:string,
                status:string,
                startTime:string,
                endTime:string,
                startAddress:string,
                endAddress:string,
                skip:number,
                count:number
            ){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.CspOrder.getCspOrderList(
                orderId,
                status,
                startTime,
                endTime,
                startAddress,
                endAddress,
                skip,
                count

            ),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //获取发布订单详情
        getCspOrder:function(id:string){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.CspOrder.getCspOrder(id),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //添加发布订单
        //参数类型未知，后续再加
        //attention!!!
        addCspOrder:function(obj){
            Vue.use(VueResource);
            return Vue.http.post(baseUrl+routeService.CspOrder.addCspOrder(),obj,
            {
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: false
            }).then(function(response) {
                var data = response.data;
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //修改发布列表
        editCspOrder:function(id:string){
            Vue.use(VueResource);
            return Vue.http.put(baseUrl+routeService.CspOrder.editCspOrder(id),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //删除发布列表
        deleteCspOrder:function(id:string){
            Vue.use(VueResource);
            return Vue.http.delete(baseUrl+routeService.CspOrder.deleteCspOrder(id),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        }
    };
    var CustomerRepresentative={
        //获取客户列表
        getCustomerList:function(
                enterPriseId:string,
                skip:number,
                count:number
            ){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.CustomerRepresentative.getCustomerList(enterPriseId,skip,count),{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
      
    };
    var Goods={
        //获取货物列表
        getDoodsList:function(
            enterPriseId:string,
            goodsTypeId:string,
            skip:number,
            count:number
        ){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Goods.getGoodsList(enterPriseId,goodsTypeId,skip,count),{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
       
    };
    var GoodsType={
        //获取货物列别列表
        getDoodsTypeList:function(
            enterPriseId:string,
            skip:number,
            count:number
        ){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.GoodsType.getGoodsTypeList(enterPriseId,skip,count),{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
       
    };
    var Inquiry={
        //获取询价列表
        getInquiryList:function(
            inquiryId:string,
            inquiryChildId:string,
            Origin:string,
            Destination:string,
            status:string,
            begin:string,
            end:string,
            skip:number,
            count:number
            ){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Inquiry.getInquiryList(
                inquiryId,
                inquiryChildId,
                Origin,
                Destination,
                status,
                begin,
                end,
                skip,
                count
            ),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //获取询价详情
        getInquiry:function(id:string){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Inquiry.getInquiry(id),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //修改询价状态
        editInquiry:function(id:string,status:any){
            Vue.use(VueResource);
            return Vue.http.put(baseUrl+routeService.Inquiry.editInquiry(id),status,{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
    };
    var LinePrice={
        //获取线路报价列表
        getLinePriceList:function(
            enterPriseId:string,
            goodsTypeId:string,
            goodsId:string,
            skip:number,
            count:number

            ){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.LinePrice.getLinePriceList(
                enterPriseId,
                goodsTypeId,
                goodsId,
                skip,
                count
            ),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //获取线路报价详情
        getLinePrice:function(id:string){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.LinePrice.getLinePrice(id),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
    }
    var Location={
            getLocation:function(phone){
                Vue.use(VueResource);
                return Vue.http.get(baseUrl+routeService.Location.getLocation(phone),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
    }
    var Order={
        //获取订单列表
        getOrderList:function(
                orderId:string,
                status:string,
                deliveryBegin:string,
                deliveryEnd:string,
                origin:string,
                destination:string,
                skip:number,
                count:number
            ){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Order.getOrderList(
                orderId,
                status,
                deliveryBegin,
                deliveryEnd,
                origin,
                destination,
                skip,
                count
            ),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //获取订单详情
        getOrder:function(id:string){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Order.getOrder(id),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
    };
    var Project={
        //获取工程列表
        getProjectList:function(
                enterPriseId:string,
                skip:number,
                count:number
            ){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Project.getProjectList(enterPriseId,skip,count),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
        //获取工程详情
        getProject:function(id:string){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Project.getProject(id),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        },
    };
    var Settle={
        //获取结算方列表
        getSettleList:function(
            enterPriseId:string,
            skip:number,
            count:number
        ){
            Vue.use(VueResource);
            return Vue.http.get(baseUrl+routeService.Settle.getSettleList(enterPriseId,skip,count),{},{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: true
            }).then(function(response) {
                var data = response.data['data'];
                return data;
            }, function(response) {
                // handle error
                return response;
            })
        }
    };
    var User={
        //登陆
        login:function(userName,passWord){
            Vue.use(VueResource);
            var obj={
                userName:userName,
                password:passWord
            };
            return Vue.http.post(baseUrl+routeService.User.login(),obj,{
                headers: {
                    "X-Requested-With": "XMLHttpRequest"
                },
                emulateJSON: false
            }).then(function(response) {
                var data = response.data['data'];
                // console.log("login service")
                // console.log(data)
                return data;
            }, function(response) {
                // handle errordata
                return response;
            })
        },
      


        //修改密码
        updatePassword:function(oldPassword,password,rePassword){
            Vue.use(VueResource);
            return Vue.http.put(baseUrl+routeService.User.updatePassword,{
                oldPassword:oldPassword,
                password:password,
                rePassword:rePassword
            },
            {
                headers: {
                    "X-Requested-With": "XMLHttpRequest",
                   
                },
                emulateJSON: false
            }).then(function(response) {
                
                return response.data['data'];
            }, function(response) {
                // handle error
                return response;
            })
        }
    }

    
    return {
        upload: upload,
        Storage:Storage,
        Attachment:Attachment,
        Area:Area,
        CspInquiry:CspInquiry,
        CspOrder:CspOrder,
        CustomerRepresentative:CustomerRepresentative,
        Goods:Goods,
        GoodsType:GoodsType,
        Inquiry:Inquiry,
        LinePrice:LinePrice,
        Location:Location,
        Order:Order,
        Project:Project,
        Settle:Settle,
        User:User,
        baseUrl:baseUrl
    };
}
